package main.java.responsibility;

/**
 * 抽象处理者
 */
public abstract class Handler {
    protected static final int NUM_ONE = 1;
    protected static final int NUM_THREE = 3;
    protected static final int NUM_SEVEN = 7;

    private int numStart;
    private int numEnd;
    //声明后继者
    private Handler nexHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置后继者
    public void setNexHandler(Handler nexHandler) {
        this.nexHandler = nexHandler;
    }

    //处理方法
    public abstract void handleLeave(LeaveRequest leave);

    public final void submit(LeaveRequest leave) {
        //该领导进行审批
        this.handleLeave(leave);
        if (this.nexHandler != null && leave.getNum() > this.numEnd) {
            //提交给下一部门进行审批
            this.nexHandler.submit(leave);
        } else {
            System.out.println("流程结束");

        }
    }
}
